package semail.tt1.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.util.StringUtils;
import semail.tt1.entity.TtTest;

import java.util.List;

@Mapper
public interface TtTest2Mapper {

    @SelectProvider(type = TtTest2Provider.class, method = "queryTest")
//    @Results({
//            @Result(property = "id", column = "id"),
//            @Result(property = "ttName", column = "tt_name"),
//            @Result(property = "ttDesc", column = "tt_desc")
//    })
    List<TtTest> queryUser(TtTest user);

    class TtTest2Provider{
        public String queryTest(TtTest test) {
            StringBuilder sql = new StringBuilder("select * from tt_test where 1=1 ");
            if(!StringUtils.isEmpty(test.getTtName())) {
                sql.append(String.format("and tt_name like '%s'", "%"+test.getTtName()+"%"));
            }

            return sql.toString();
        }
    }
}

